<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <script src="https://lib.baomitu.com/socket.io/4.1.3/socket.io.js"></script> 
  </head>
  <body>
    <h1>Hello World!</h1>
    We are using Node.js <span id="node-version"></span>,
    Chromium <span id="chrome-version"></span>,
    and Electron <span id="electron-version"></span>.
    <input class="button-primary" value="Ping" id="Ping" type="button">
    <!-- You can also require other files to run in this process -->
    <script src="./renderer.js">
        const {ipcRenderer} = require('electron');
        var desktopCapturer = require('electron').desktopCapturer;

        var socket = io.connect('ws://127.0.0.1:3000'); 
        socket.emit("message", {"name" : 'electron', "msg" : "hello world" });


        socket.on("message", function(obj) {
          console.log(obj);
        });

          
        desktopCapturer.getSources(  { types: ['window'], thumbnailSize: { width: 1200, height: 1200 } },
        (error, sources) => {
          if (!error) {
              console.log(error)
            if (sources && sources.length > 0) {
              console.log(1)
              console.log(sources)
            }
          } 
        }
      )
      
setInterval(()=>{
  socket.emit("message", {"name" : 'electron', "msg" : "hello world" });
    desktopCapturer.getSources(  { types: ['window'], thumbnailSize: { width: 1200, height: 1200 } },
        (error, sources) => {
          if (!error) {
              console.log(error)
            if (sources && sources.length > 0) {
              console.log(1)
              console.log(sources)
            }
          } 
        }
      )
},5000)


        document.getElementById("Ping").addEventListener('click', () => {
            ipcRenderer.send("asynchronous-message","ping?="+new Date().getTime())
        });


        ipcRenderer.on('asynchronous-reply', (event, arg) => {
            console.log(arg) // prints "pong"
            console.log("event=",event);
        })

    </script>
  </body>
</html>
